﻿using System;
#if (!SILVERLIGHT)
using System.Runtime.Serialization;
#endif

namespace Microsoft.Services.Clab.UI.Mvvmc
{
#if (!SILVERLIGHT)
    [Serializable]
#endif
    public class ControllerException : Exception
    {
        public ControllerException()
        { }

        public ControllerException(string message)
            : base(message)
        { }

        public ControllerException(string message, Guid controllerId, string actionName)
            : base(message)
        {
            this.ControllerId = controllerId;
            this.ActionName = actionName;
        }

        public ControllerException(string message, Exception inner)
            : base(message, inner)
        { }

        public ControllerException(string message, Guid controllerId, string actionName, Exception inner)
            : base(message, inner)
        {
            this.ControllerId = controllerId;
            this.ActionName = actionName;
        }

        public Guid ControllerId { get; private set; }
        public string ActionName { get; private set; }

#if (!SILVERLIGHT)
        protected ControllerException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        { }

        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            base.GetObjectData(info, context);
            info.AddValue("ControllerActionName", this.ActionName, typeof(string));
            info.AddValue("ControllerControllerId", this.ControllerId, typeof(string));
        }
#endif
    }
}
